package edu.hebeu.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import edu.hebeu.entity.Attendance;
import edu.hebeu.entity.Employee;
import edu.hebeu.mapper.AttendanceMapper;
import edu.hebeu.mapper.EmployeeMapper;
import edu.hebeu.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attendance> implements AttendanceService {
    @Autowired
   private  AttendanceMapper attendanceMapper;
@Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Attendance> selectLis(Integer employeeNumber) {
        EntityWrapper<Attendance> wrapper = new EntityWrapper<>();
        wrapper.orderBy("id",false);
        wrapper.eq("employee_number",employeeNumber);
        List<Attendance> list = baseMapper.selectList(wrapper);
        for (Attendance attendance : list) {
          setObject(attendance);
        }
        return list;
    }

    private void setObject(Attendance attendance) {
        Integer employeeNumber = attendance.getEmployeeNumber();
        Employee employee=employeeMapper.selectByNumber(employeeNumber);
        attendance.setEmployee(employee);


    }
}
